package com.braveman.im.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.braveman.im.R;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.ui.widget.TitleBarView;
import com.ht.baselibs.utils.ActivityUtils;
import com.vondear.rxtools.RxBarTool;

import java.util.ArrayList;

public class GiveWhosCanLookActivity extends BaseActivity {
    private RelativeLayout mRlEveryoneCanLook;
    private ImageView mIvEveryoneCanLook;
    private RelativeLayout mRlNoOneCanLook;
    private ImageView mIvNoOneCanLook;
    private RelativeLayout mRlFriendCanLook;
    private ImageView mIvFriendCanLook;
    private RelativeLayout mRlFriendNoLook;
    private ImageView mIvFriendNoLook;
    private String canLook = "all";
    public static final int GIVE_NAME_CODE = 11212;
    private ArrayList<String> canLookList = new ArrayList<>();

    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("给谁看").setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.finishActivity(GiveWhosCanLookActivity.this);
            }
        });
        mTitleBarView.addActions(new TitleBarView.Action(R.color.color_19, "完成") {
            @Override
            public void performAction(View view) {
                Intent intent = new Intent();
                intent.putExtra("canLook", canLook);
                if (canLookList != null) {
                    intent.putStringArrayListExtra("canLookList", canLookList);
                }
                setResult(RESULT_OK, intent);
                ActivityUtils.finishActivity(GiveWhosCanLookActivity.this);
            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_give_whos_can_look;
    }

    @Override
    protected void initChildView() {
        mRlEveryoneCanLook = (RelativeLayout) findViewById(R.id.rl_everyone_can_look);
        mIvEveryoneCanLook = (ImageView) findViewById(R.id.iv_everyone_can_look);
        mRlNoOneCanLook = (RelativeLayout) findViewById(R.id.rl_no_one_can_look);
        mIvNoOneCanLook = (ImageView) findViewById(R.id.iv_no_one_can_look);
        mRlFriendCanLook = (RelativeLayout) findViewById(R.id.rl_friend_can_look);
        mIvFriendCanLook = (ImageView) findViewById(R.id.iv_friend_can_look);
        mRlFriendNoLook = (RelativeLayout) findViewById(R.id.rl_friend_no_look);
        mIvFriendNoLook = (ImageView) findViewById(R.id.iv_friend_no_look);
    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void setChildViewListener() {
        mRlEveryoneCanLook.setOnClickListener(this);
        mRlNoOneCanLook.setOnClickListener(this);
        mRlFriendCanLook.setOnClickListener(this);
        mRlFriendNoLook.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        Reselect();
        switch (v.getId()) {
            case R.id.rl_everyone_can_look:
                mIvEveryoneCanLook.setVisibility(View.VISIBLE);
                canLook = "all";
                break;
            case R.id.rl_no_one_can_look:
                mIvNoOneCanLook.setVisibility(View.VISIBLE);
                canLook = "justMe";
                break;
            case R.id.rl_friend_can_look:
                mIvFriendCanLook.setVisibility(View.VISIBLE);
                canLook = "justSelected";
                ActivityUtils.startActivityForResult(GiveWhosCanLookActivity.this, SelectFriendsActivity.class, GIVE_NAME_CODE);
                break;
            case R.id.rl_friend_no_look:
                mIvFriendNoLook.setVisibility(View.VISIBLE);
                canLook = "excludeSelected";
                ActivityUtils.startActivityForResult(GiveWhosCanLookActivity.this, SelectFriendsActivity.class, GIVE_NAME_CODE);
                break;
        }
    }


    private void Reselect() {
        mIvEveryoneCanLook.setVisibility(View.GONE);
        mIvNoOneCanLook.setVisibility(View.GONE);
        mIvFriendCanLook.setVisibility(View.GONE);
        mIvFriendNoLook.setVisibility(View.GONE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case GIVE_NAME_CODE:
                    if (data != null) {
                        canLookList = data.getStringArrayListExtra("friendsId");
                    }
                    break;
            }

        }
    }
}
